package com.joycessh.common.lang;

import lombok.Data;

import java.io.Serializable;

/**
 * @Author Joycessh
 * @Description
 * @Date 8/17/19 3:38 PM
 */
@Data
public class Result implements Serializable {

    private Integer code;
    private Integer status;
    private String msg;
    private Object data;
    private String action;

    public static Result succ(Object data) {
        return succ("操作成功", data);
    }

    public static Result succ(String msg, Object data) {
        return succ(msg, data, null);
    }

    public static Result succ(String msg, Object data, String action) {
        Result result = new Result();

        result.setCode(0);
        result.setStatus(0);
        result.setMsg(msg);
        result.setData(data);
        result.setAction(action);

        return result;
    }

    public static Result fail(String msg) {
        return fail(msg, null);
    }

    public static Result fail(String msg, Object data) {
        Result result = new Result();

        result.setCode(-1);
        result.setStatus(-1);
        result.setMsg(msg);
        result.setData(data);

        return result;
    }
}
